/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Clases;
import javax.swing.JComboBox;
import java.util.Calendar;


/**
 *
 * @author Matias de la torre
 */
public class Fechas {

    Calendar calendar;

    public Fechas(){
    calendar = Calendar.getInstance();
    }

    private void CargarDias30(JComboBox JCombo){
        for (int i=1;i<=9;i++){
            JCombo.addItem("0"+String.valueOf(i));
        }
        for (int i=10;i<=30;i++){
            JCombo.addItem(String.valueOf(i));
        }
    }

    private void CargarDias31(JComboBox JCombo){
         for (int i=1;i<=9;i++){
            JCombo.addItem("0"+String.valueOf(i));
        }
     for (int i=10;i<=31;i++){
            JCombo.addItem(String.valueOf(i));
        }
    }
    private void CargarDias28(JComboBox JCombo){
         for (int i=1;i<=9;i++){
        JCombo.addItem("0"+String.valueOf(i));
        }
     for (int i=10;i<=28;i++){
        JCombo.addItem(String.valueOf(i));
        }
    }

     private void CargarDias29(JComboBox JCombo){
          for (int i=1;i<=9;i++){
        JCombo.addItem("0"+String.valueOf(i));
        }
     for (int i=10;i<=29;i++){
        JCombo.addItem(String.valueOf(i));
        }
    }

    public void CargarMeses(JComboBox JCombo){
        
     for (int i=1;i<=9;i++){
        JCombo.addItem("0"+String.valueOf(i));
        }
     for (int i=10;i<=12;i++){
        JCombo.addItem(String.valueOf(i));
        }
    }

    public void CargarAños(JComboBox JCombo){
         for (int i=1900;i<=calendar.get(Calendar.YEAR);i++){
             JCombo.addItem(String.valueOf(i));
        }
    }
    public void CargarDias(JComboBox Dia,JComboBox Mes ,JComboBox Año){


Dia.removeAllItems();
        boolean bisiesto = false; //se crea una variable booleana tipo bantera inicializada en false
        if(Integer.parseInt(String.valueOf(Año.getSelectedItem())) % 4 == 0){//Es bisiesto el signo de % obtiene el residuo de año/4
            bisiesto = true;
        }
    switch(Integer.parseInt(String.valueOf(Mes.getSelectedItem()))){ //validamos el numero del mes
        case 1: case 3: case 5: case 7: case 8 : case 10: case 12:
            CargarDias31(Dia);
            break;
        case 4: case 6: case 9: case 11:
            CargarDias30(Dia);
            break;
        case 2:
            if(bisiesto)
                CargarDias29(Dia);
            else
                CargarDias28(Dia);
            break;
     }

}
}

